//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

public class demo_1041 {
    public demo_1041() {
    }

    public boolean isRobotBounded(String instructions) {
        int x = 0;
        int y = 0;
        int direction = 0;

        for(int i = 0; i < instructions.length(); ++i) {
            if (instructions.charAt(i) == 'G') {
                switch (direction) {
                    case 0:
                        ++y;
                        break;
                    case 1:
                        ++x;
                        break;
                    case 2:
                        --y;
                        break;
                    case 3:
                        --x;
                }
            } else if (instructions.charAt(i) == 'L') {
                if (direction == 0) {
                    direction = 3;
                } else {
                    --direction;
                }
            } else if (direction == 3) {
                direction = 0;
            } else {
                ++direction;
            }
        }

        if (x == 0 && y == 0) {
            return true;
        } else {
            return direction != 0;
        }
    }
}
